/**
	Constructs a 

	@author Francis Villanueva
	@version 2006-10-17
	@copyright (c) 2006 The Chopping Block, Inc.. All rights reserved.

	@usage

	- Activate with:
	<code>

	</code>

*/

/*import Classes.*;*/
import timber.ui.*;
import com.mosesSupposes.fuse.*;

class VideoPlayerView {
		
	private var controller:Object;
	private var view:Object;

	//main components
	private var rootMC:MovieClip;
	private var bg_mc:MovieClip;
	private var player_mc:MovieClip;
	private var preview_mc:MovieClip;
	public var controls_mc:MovieClip;
	public var options_mc:MovieClip;
	private var nowPlaying_mc:MovieClip;
	private var playlist_mc:MovieClip;
	private var fullScreenBtn:MovieClip;	
	
	//option boxes
	public var embedBox:MovieClip;
	public var linkBox:MovieClip;
	public var emailBox:MovieClip;
	public var prefsBox:MovieClip;

	//misc
	private var bigPlayBtn:MovieClip;
	private var logo_mc:MovieClip;
	private var lastSpeedButtonClicked:MovieClip;
	private var lastPLEntryClicked:MovieClip;
	public var lastOptionClicked:MovieClip;

	//ad components
	private var videoAdHolder:MovieClip;
	public var adClick_mc:MovieClip;
	public var adTextHolder_mc:MovieClip;
	
	private var ears:Object;
	private var txtListener:Object = new Object();
	
	//dimensions
	private var videoWidth:Number;
	private var videoHeight:Number;
	private var viewportWidth:Number;
	private var viewportHeight:Number;
	private var nowPlayingWidth:Number = 0;
	private var nowPlayingHeight:Number = 0;
	private var layout:String;

	//tool tips
	//private var toolTip:ToolTipController;
	//private var toolTipTimer:Number;

	// ===========================================================
	// - CONSTRUCTOR 
	// ===========================================================

	function VideoPlayerView(controller:Object, rootMC:MovieClip,width:Number, height:Number) {
		trace("\t VIEW VideoPlayerView");
		this.rootMC = rootMC;
		this.controller = controller;
		//this.view = this;
		this.videoAdHolder = rootMC.videoAdHolder;
		
		this.viewportWidth = width;
		this.viewportHeight = height;
		
		this.videoWidth = width;
		this.videoHeight = height - 24;
		
		//set up zigo
		ZigoEngine.simpleSetup(Shortcuts, PennerEasing, FuseFMP);
		
		//black box to make background alway be black regardless of embed color
		bg_mc = rootMC.attachMovie('rectangle_bg_id', 'bg_mc', 1, {_width:Stage.width,_height:Stage.height});
		ZigoEngine.doTween(bg_mc, "_tint", "0000000", 0);
		
		setTextListeners();
	}

	// ===========================================================
	// - VIDEO PLAYER / CONTROLS
	// ===========================================================
		
	function createPlayer(width:Number, height:Number, npWidth:Number, npHeight:Number, plAlign:String, plVisible:Boolean, optionsAllowed:Array, fullScreenAllowed:Boolean, color:String) {	
		trace("\t VIEW createPlayer");
				
		//now playing
		if(plVisible && plAlign == "above") {
			this.nowPlayingWidth = npWidth;
			this.nowPlayingHeight = npHeight;
			
			nowPlaying_mc = rootMC.attachMovie('nowPlaying_id', 'now_playing_mc', 2);
			nowPlaying_mc.bg_mc._height = this.nowPlayingHeight+20;
			nowPlaying_mc.bg_mc._width = this.viewportWidth;
			nowPlaying_mc.line_mc._y = (this.nowPlayingHeight + 20) - nowPlaying_mc.line_mc._height;
			nowPlaying_mc.line_mc._width = this.viewportWidth;
			nowPlaying_mc.closedY = 0 - (this.nowPlayingHeight + 20);
			nowPlaying_mc._y = nowPlaying_mc.closedY;
			nowPlaying_mc.label_txt.autoSize = true;
			nowPlaying_mc.label_txt.multiline = true;
			nowPlaying_mc.label_txt._x = this.nowPlayingWidth + 20;
			nowPlaying_mc.label_txt._width = this.viewportWidth - (nowPlaying_mc.label_txt._x + 20);
			nowPlaying_mc.onRelease = DelegateArgs.create(controller, controller.optionSelected, "Playlist", true);
		}
		
		//preview image
		preview_mc = rootMC.attachMovie('imageLoader','preview_mc', 15);
		
		//ad click movieclip
		adClick_mc = rootMC.attachMovie('rectangle_bg_id','adClick_mc', 21, {_width:this.videoWidth,_height:this.videoHeight,_alpha:0});
		
		//ATTACH FLV COMPONENT
		player_mc = rootMC.attachMovie('FLVPlayback', 'flvPlayer', 20);

		player_mc.originY = 0;
		//player_mc.maintainAspectRatio = false;
		player_mc.setSize(this.videoWidth, this.videoHeight);
				
		//CONTROLS
		var controlsHolder = rootMC.createEmptyMovieClip('controlsHolder', 40);
		       
		//secondary nav
		options_mc = controlsHolder.createEmptyMovieClip('options_mc', controlsHolder.getNextHighestDepth());
		//background chrome
		options_mc.attachMovie('options_bg_id', 'bg_mc', options_mc.getNextHighestDepth());
		
		options_mc.bg_mc._width = this.viewportWidth;
		options_mc.bg_mc._alpha = 75;

		var defaultOptionsArr = ["Email", "Link", "Embed", "Prefs"];

		//remove out any options that are set to false
		var optionsCount = defaultOptionsArr.length;
		var optionsArr = new Array();
		for(var i =0;i<optionsCount;i++) {
			var optionState = optionsAllowed[i];
			var option = defaultOptionsArr[i];
			if(optionState) {
				optionsArr.push(option);
			}
		}

		//playlist button (if needed)
		if(plVisible && plAlign == "above") {
			optionsArr.unshift("Playlist");
		}
		
		var optionsCount = optionsArr.length;

		var optionWidth = this.viewportWidth/optionsCount;
		for(var i =0;i<optionsCount;i++) {
			var btn = options_mc.attachMovie('btn_'+optionsArr[i].toLowerCase()+'_id', 'btn_'+optionsArr[i].toLowerCase()+'_mc', options_mc.getNextHighestDepth());
			btn.id = optionsArr[i];
			//mouse events
			btn.onRelease = DelegateArgs.create(controller, controller.optionSelected, btn.id, true);
			btn.onRollOver = DelegateArgs.create(this, this.optionOver, optionsArr[i]);
			btn.onRollOut = DelegateArgs.create(this, this.optionOut, optionsArr[i]);
			btn.enabled = false;

			//position
			btn._x = Math.round((optionWidth/2 - btn._width/2) + (i*optionWidth));
			btn._y = 1;
			
			//dividers
			if(i != 0) {
				var divider = options_mc.attachMovie('divider_id', 'divider'+i, options_mc.getNextHighestDepth(), {_x:i*optionWidth});
				divider._y = 2;
				divider._alpha = 75;
			} 
		}
		
		options_mc._y = this.viewportHeight - 24;
		options_mc.openY = this.viewportHeight - 38;
		options_mc.closeY = this.viewportHeight - 24;

		//buttons
		controls_mc = controlsHolder.attachMovie('videoControls_id', 'videoControls_mc', controlsHolder.getNextHighestDepth());
		
		//set control y pos
		controls_mc._y = this.viewportHeight - 24;

		//set background width
		controls_mc.bg_mc._width = this.viewportWidth;
		
		//play/pause/stop buttons functionality
		var btn_play = controls_mc.btn_play_mc;
		var btn_pause = controls_mc.btn_pause_mc;
		var btn_next = controls_mc.btn_next_mc;
		var btn_prev = controls_mc.btn_prev_mc;
		
		btn_play.onRelease = DelegateArgs.create(controller, controller.playVideo);
		btn_pause.onRelease = DelegateArgs.create(controller, controller.pauseVideo);
		//controls_mc.btn_stop_mc.onRelease = DelegateArgs.create(controller, controller.stopVideo);
			                               
		//set previous and next buttons
		btn_next.onRelease = DelegateArgs.create(controller, controller.next);
		btn_prev.onRelease = DelegateArgs.create(controller, controller.prev);
		
		//vars for right aligning elements after seek bar
		var rightAlignBuffer = 6;
		var rightAlignX = this.viewportWidth - rightAlignBuffer;

		//fullscreen button
		if(fullScreenAllowed) {
			var btn_fs = controls_mc.btn_fullscreen_mc;
			rightAlignX -= btn_fs._width;
			btn_fs._x = rightAlignX;
			btn_fs.onRelease = DelegateArgs.create(controller, controller.toggleFullScreen);
		} else {
			controls_mc.btn_fullscreen_mc._visible = false;
		}

		//set volume button
		controls_mc.btn_volume_mc.onRelease = DelegateArgs.create(controller, controller.volumePressed);
		
		//update right align
		rightAlignX -= controls_mc.btn_volume_mc._width;
		
		controls_mc.btn_volume_mc._x = rightAlignX;
				
		//set volume slider visual props
		var vol_slider = controls_mc.slider_volume_mc;
		vol_slider._x = rightAlignX + 2;
		vol_slider.hideY = vol_slider._y;
		vol_slider.showY = 0 - Math.ceil(vol_slider._height) - 20;
		vol_slider.bg_mc._alpha = 50;
			
		//set volume slider functional stuff
		vol_slider.onLoad = DelegateArgs.create(this, volumeBarReady);
			               
		vol_slider.onChange = DelegateArgs.create(controller, controller.setVolume, vol_slider.getValue());
		
		//apply color to volume handle
		ZigoEngine.doTween(vol_slider.handle.bg_mc, "_tint", color, 0);
		
		//volume slider mouseclick bg check
		var bg = controls_mc.attachMovie('rectangle_bg_id', 'vol_slider_bg_mc', controls_mc.getNextHighestDepth());
		bg._alpha = 0;
		bg._width = vol_slider._width+10;
		bg._height = vol_slider._height + 20;

		bg._x = rightAlignX - 4;
		bg._y = 0 - bg._height;//vol_slider.showY;
			
		//right time display
		var timeBox = controls_mc.timeLeft_mc;
		
		//update right align
		rightAlignX -= controls_mc.timeLeft_mc._width;
		
		timeBox._x = rightAlignX;
		
		//SEEKBAR
		//built-in seek bar
		//player_mc.seekBar = controls_mc.seekBar_mc;
		
		var seekbar = controls_mc.slider_seek_mc;
		seekbar.progress_mc._height = 0;
		
		var newHeight = Math.ceil(rightAlignX - seekbar._x - seekbar.bg_bar._y - rightAlignBuffer);
		
		seekbar.bg_bar._height = newHeight;
		
		var normalHeight = Math.round((newHeight*100)/seekbar.bg_bar._yscale);
		
		seekbar.progress_mc.scale = 100/normalHeight;
		
		seekbar.progress_mc.controller = controller;
		seekbar.progress_mc.onRelease = function() {
			//trace("this._ymouse "+(this.scale*this._ymouse));
			var newPos = Math.round(this.scale*this._ymouse);
			trace("newPos "+newPos)
			this.controller.seekVideo(newPos, true);
		};
		
		//DelegateArgs.create(controller, controller.seekVideo, seekbar.progress_mc._ymouse);
		
		//apply color to handle
		ZigoEngine.doTween(seekbar.handle.bg_mc, "_tint", color, 0);
		
		seekbar.onLoad = function() {
			//trace("SEEKBAR READDDYYYYYYYYYY");
			seekbar.setMax(100);
			seekbar.setMin(0);
			seekbar.setSize(newHeight+0)
			seekbar.update();
		}
		
		//when seekbar value changes
		seekbar.onChange = DelegateArgs.create(controller, controller.seekVideo, seekbar.getValue(), seekbar.getDragging());
		
		seekbar.handle.controller = controller;
		
		/*seekbar.handle.onRelease = function() {
			this._parent.dragging = false;
			this.stopDrag();
			delete (this.onEnterFrame);
			this.controller.seekVideo(this._parent.getValue());
		}
		
		seekbar.handle.onPress = function() {
			this._parent.dragging = true;
			this.startDrag(false, this._x, this._parent.handlemin, this._x, this._parent.handlemax);
			this.onEnterFrame = function() {
				this._parent.setValue(Math.ceil((this._y-this._parent.handlemin) * (this._parent.range)/this._parent.channelheight + this._parent.minval));
			}
			
			this.controller.seekVideo(this._parent.getValue());
		}	*/
		/*	
		seekbar.handle.onRelease = function() {
			//trace("blah")
			//DelegateArgs.create(controller, controller.seekVideo, seekbar.getValue());
			super.onRelease();
		}*/
		
		//add colors for rollover and rollouts
		for (var i in controls_mc) {
			var mc = controls_mc[i];
			mc.accentColor = color;
			mc.over = false;
			if(mc.onRelease != undefined) {
				mc.onRollOver = function() {
					this.over = true;
					ZigoEngine.doTween(this.icon_mc, "_tint", color, 0);
				}
				mc.onRollOut = mc.onReleaseOutside = function() {
					this.over = false;
					ZigoEngine.doTween(this.icon_mc, "_tint", null , 0);
				}
				mc.onPress = function() {
					ZigoEngine.doTween(this.icon_mc, "_tint", "#CCCCCC", 0);
				}
			}
		}
		
		//mask for controls
		var mask = controlsHolder.attachMovie('rectangle_bg_id', 'mask_mc', controlsHolder.getNextHighestDepth(), {_width:this.viewportWidth,_height:this.viewportHeight});
		controls_mc.setMask(mask);
		
		//ad text set to invisible by default
		adTextHolder_mc = controls_mc.adTextHolder_mc;
		adTextHolder_mc.maskWidth = newHeight;
		adTextHolder_mc._visible = false;
		var adTextMask = controls_mc.attachMovie('rectangle_bg_id', 'adTextmask_mc', controls_mc.getNextHighestDepth(), {_width:newHeight,_height:adTextHolder_mc._height,_x:adTextHolder_mc._x,_y:adTextHolder_mc._y});
		adTextHolder_mc.setMask(adTextMask);		
		
		//RETURN VIDEO PLAYER BACK TO CONTROLLER
		return player_mc;
	};
	
	function updateProgressBar(percent:Number){
		////trace("\t VIEW updateProgressBar ");
		var progressBar = controls_mc.slider_seek_mc.progress_mc;
		var bgBar = controls_mc.slider_seek_mc.bg_bar;
		controls_mc.slider_seek_mc.progress_mc._height = (bgBar._height*percent)/100;
	};
	
	function playVideo(){
		var btn = controls_mc.btn_play_mc;
		buttonReset(btn);
	};
	
	function pauseVideo() {
		var btn = controls_mc.btn_pause_mc;
		buttonReset(btn);
	};

	function toggleSeekBar(state:Boolean){
		//trace("\t VIEW hideSeekBar");
		var seekbar = controls_mc.slider_seek_mc;
		if(seekbar._visible != state) {
			seekbar._visible = state;			
		}
	};

	function toggleChrome(state:Boolean, duration:Number){
		//trace("VIEW toggleChrome "+state + " "+ duration);
		if(state) {
			if(duration > 0) {
				if(ZigoEngine.isTweening(controls_mc) == false && controls_mc._alpha != 100) {
					ZigoEngine.doTween(controls_mc, ["_fade"], [100], duration, "easeInOutExpo", 0);
				} else {
					if(ZigoEngine.isTweening(controls_mc)) {
						ZigoEngine.removeTween(controls_mc);
					}
					controls_mc._alpha = 100;
					controls_mc._visible = state;
				}
			} else {
				if(ZigoEngine.isTweening(controls_mc)) {
					ZigoEngine.removeTween(controls_mc);
				}
				controls_mc._alpha = 100;
				controls_mc._visible = state;				
			}
		} else {
			if(duration > 0) {
				ZigoEngine.doTween(controls_mc, ["_fade"], [0], duration, "easeInOutExpo", 0);
			} else {
				if(ZigoEngine.isTweening(controls_mc)) {
					ZigoEngine.removeTween(controls_mc);
				}
				controls_mc._alpha = 0;
				controls_mc._visible = state;				
			}
			options_mc._visible = state;
		}
	};

	function updateTimeDisplay(timePassed:String, timeLeft:String) {
		////trace("\t VIEW updateTimeDisplay");
		controls_mc.timePassed_mc.time_txt.text = timePassed;
		controls_mc.timeLeft_mc.time_txt.text = timeLeft;
	}

	function showPreview(image:String, duration:Number){
		trace("\t VIEW showPreview");

		preview_mc._visible = false;
		preview_mc.load(image);
		
		var ears = {};
		ears.onLoad = DelegateArgs.create(controller, controller.previewLoaded);
		preview_mc.addListener(ears)
	};
	
	function previewLoaded(playlistOpen:Boolean){
		trace("\t VIEW previewLoaded");
		
		if(!controller.fullScreenEnabled) {
			if(!playlistOpen) {
//				ZigoEngine.doTween(preview_mc, ["_width","_height","_x","_y"], [this.videoWidth, this.videoHeight, 0, 0], 0, "easeInOutExpo", 0);
				preview_mc._x = preview_mc._y = 0;
				preview_mc._width = this.videoWidth;
				preview_mc._height = this.videoHeight;
				
			} else {
//				ZigoEngine.doTween(preview_mc, ["_width","_height","_x","_y"], [this.nowPlayingWidth, this.nowPlayingHeight, 10, 10], 0, "easeInOutExpo", 0);
				preview_mc._x = preview_mc._y = 10;
				preview_mc._width = this.nowPlayingWidth;
				preview_mc._height = this.nowPlayingHeight;
				
			}			
		} else {
			preview_mc._width = Stage.width;
			preview_mc._height = Stage.height;
		}
		
		preview_mc._visible = true;	
	};
	
	function hidePreview(){
		trace("\t VIEW hidePreview");
		preview_mc.unload();
		preview_mc._visible = false;
	};

	function showBigPlayButton(color:String){
		trace("\t VIEW showBigPlayButton");
		if(bigPlayBtn == undefined) {
			bigPlayBtn = rootMC.attachMovie('bigPlayButton_id', 'bigPlayBtn_mc', 1000);
		}
	
		//center button
		this.centerBigPlayButton(false);
		
		//drop shadow
		FuseFMP.setFilterProps(this.bigPlayBtn, 'DropShadow', { blurX:10, blurY:10, quality:5, angle:0, distance:0, color:"#666666"});
		
		//mouse events
		bigPlayBtn.onRollOver = function() {
			ZigoEngine.doTween(this.icon_mc, "_tint", color, 0);
		}
		
		bigPlayBtn.onRollOut = function() {
			ZigoEngine.doTween(this.icon_mc, "_tint", null, 0);
		}
		
		bigPlayBtn.onRelease = DelegateArgs.create(controller, controller.playVideo);
	};
	
	function hideBigPlayButton(){
		trace("\t VIEW hideBigPlayButton");
		if(bigPlayBtn != undefined) {
			bigPlayBtn.removeMovieClip();			
		}
	};
	
	function centerBigPlayButton(fullscreen:Boolean) {
		var btnWidth = bigPlayBtn._width;
		var btnHeight = bigPlayBtn._height;
		
		if(fullscreen) {
			bigPlayBtn._x = Stage.width/2 - (btnWidth/2);
			bigPlayBtn._y = Stage.height/2 - (btnHeight/2);			
		} else {
			bigPlayBtn._x = this.viewportWidth/2 - (btnWidth/2);
			bigPlayBtn._y = this.viewportHeight/2 - (btnHeight/2);
		}
		
	}
	
	// ===========================================================
	// - VOLUME
	// ===========================================================

	function volumeBarReady(){
		//trace("\t VIEW volumeBarReady");
		controls_mc.slider_volume_mc.setMax(100);
		controls_mc.slider_volume_mc.setMin(0);
		controls_mc.slider_volume_mc.update();
		//got to get part working to set position of handle
		controls_mc.slider_volume_mc.setValue((100-player_mc.volume));
	};
	
	function volumePressed(state:Boolean) {
		//trace("\t VIEW volumePressed");
		var slider = controls_mc.slider_volume_mc;
		if(state) {
			ZigoEngine.doTween(slider, ["_y"], [slider.showY], .75, "easeInOutExpo", 0);
		} else {
			ZigoEngine.doTween(slider, ["_y"], [slider.hideY], .75, "easeInOutExpo", 0);
		}
	};

	// ===========================================================
	// - PLAYLIST
	// ===========================================================

	function createPlaylist(videos:Array, align:String, thumbWidth:Number, thumbHeight:Number, color:String, titlefontSize:String, descFontSize:String, openAtStart:Boolean){
		//trace("\t VIEW createPlaylist");
		switch (align) {
			case "right":
				var plX = this.viewportWidth;
				var plY = 0;
				var entryWidth = Stage.width - this.viewportWidth;
				var viewableHeight = Stage.height;
				break;
			case "bottom":
				var plX = 0;
				var plY = this.viewportHeight;
				var entryWidth = this.viewportWidth;
				var viewableHeight = Stage.height - this.viewportHeight;
				break;
			default:
				var plX = 0;
				var plY = this.viewportHeight;					
				var entryWidth = this.viewportWidth;
				var viewableHeight = this.viewportHeight - (controls_mc.bg_mc._height + nowPlaying_mc._height);
				break;
		}
		
		var entryHeight = thumbHeight + 10;
		
		if(playlist_mc != undefined) {
			playlist_mc.removeMovieClip();
		}
		
		if(videos.length > 0) {
		
			playlist_mc = rootMC.createEmptyMovieClip('playlist_mc', 30);
			playlist_mc._x = plX;
			playlist_mc._y = plY;
			playlist_mc.closedY = plY;
			(nowPlaying_mc != undefined) ? playlist_mc.openY = nowPlaying_mc._height : playlist_mc.openY = 0;
			
			var entryHolder = playlist_mc.createEmptyMovieClip('entryHolder_mc', playlist_mc.getNextHighestDepth());
			var count = videos.length;
			var altColors = ["292828", "181818"];
			var trueHeight = 0;
			for (var i=0;i<count;i++) {
				var data = videos[i];
				var plEntry = entryHolder.attachMovie('playlist_entry_id','entry'+i, i, {_y:i*entryHeight});
				//set thumbnail
				var thumb = plEntry.attachMovie('imageLoader', 'thumb_mc', 10, {_x:6,_y:5});
				thumb.setMaxSize(thumbWidth, thumbHeight, true);
				thumb.load(data.thumbnail._value);
				//thumb.setMaxSize(thumbWidth,thumbHeight);
				//set border
				plEntry.img_border_mc._width = thumbWidth+2;
				plEntry.img_border_mc._height = thumbHeight+2;
				//color border
				ZigoEngine.doTween(plEntry.img_border_mc, "_tint", color, 0);
				plEntry.img_border_mc._visible = false;
				//set entry width
				plEntry.bg_mc._width = entryWidth;
				//set entry height
				plEntry.bg_mc._height = entryHeight;
			
				//set id
				plEntry.id = data.id._value;
		
				//set text
				plEntry.label_txt._x = thumbWidth + 10;
				plEntry.label_txt.autoSize = true;
				plEntry.label_txt.multiline = true;
				plEntry.label_txt._width = entryWidth - (plEntry.label_txt._x + 25);
				var plTxt = "<font size='"+titlefontSize+"'>"+data.headline._value+"</font>";
				plTxt += newline+ "<font size='"+descFontSize+"' color='#999999'>"+data.strap._value+"</font>";
				plEntry.labelText = plTxt;
				plEntry.label_txt.htmlText = plTxt;
			
				//color entry
				ZigoEngine.doTween(plEntry.bg_mc.block_mc, "_tint", altColors[0], 0);
			
				plEntry.onRelease = DelegateArgs.create(controller, controller.entrySelected, plEntry.id);
					
				plEntry.onRollOver = DelegateArgs.create(this, entryHighlighted, plEntry, color);
			
				plEntry.onRollOut = function() {
					ZigoEngine.doTween(this.label_txt, "_colorReset", 100, 0);
				}
			
				//update true height
				trueHeight += entryHeight;
				//reverse color array to alternate colors
				altColors.reverse();
			}
				
			//sets scrollbar (if necessary)
			if (viewableHeight < trueHeight) {
				//scrollbar mask
				var mask = playlist_mc.attachMovie('rectangle_bg_id', 'mask_mc', playlist_mc.getNextHighestDepth(), {_width:entryWidth, _height:viewableHeight});
				//mask._x = this.viewportWidth;
				var scrollBarHolder = playlist_mc.createEmptyMovieClip('scrollBarHolder',playlist_mc.getNextHighestDepth());
				var scrollBar = scrollBarHolder.attachMovie('Scrollbar', 'scrollbar_mc', 1, {_x:entryWidth-12, _y:0});
				scrollBar.setSize(viewableHeight-10);
				scrollBar.setTarget(playlist_mc.entryHolder_mc);
				scrollBar.setViewSize(viewableHeight);
			
				ZigoEngine.doTween(scrollBar.handle.bg_mc, "_tint", color, 0);
				//ZigoEngine.doTween(mask, "_alpha", 50, 0);
				//scrollBar.setViewSize(100);
				scrollBar.bg_mc._height = viewableHeight - 40;
				playlist_mc.entryHolder_mc.setMask(mask);
			}
		
			if(align == "above") {
				//create close button to now playing mc (perhaps move this to where nowPlaying_mc is made)
				var closeBtn = nowPlaying_mc.attachMovie('btn_close_id', 'btn_close_mc', nowPlaying_mc.getNextHighestDepth());

				closeBtn.onRelease = DelegateArgs.create(controller, controller.hidePlaylist);

				closeBtn._x = this.viewportWidth - closeBtn._width - 6;
				closeBtn._y = 6;
			}
		
		}
		
		//entrySelected()	
	};
	
	function entryHighlighted(entry:MovieClip, color:String) {
		//trace("\t VIEW entryHighlighted");
		ZigoEngine.doTween(entry.label_txt, "_tint", color, 0);		
		controller.mouseClick();
	};
	
	function entrySelected(index:Number, color:String){
		//trace("\t VIEW entrySelected");
		//trace("\t\t\t\t index "+index);
		//reset last entry clicked/selected
		if(this.lastPLEntryClicked != undefined) {
			this.lastPLEntryClicked.enabled = true;
			lastPLEntryClicked.label_txt.htmlText = lastPLEntryClicked.labelText;
			ZigoEngine.doTween(lastPLEntryClicked.label_txt, "_tint", "#FFFFFF", 0);
			//ZigoEngine.doTween(lastPLEntryClicked.img_border_mc, "_visible", 0, 0);
			lastPLEntryClicked.img_border_mc._visible = false;
		}
		//set new entry
		var selectedEntry = playlist_mc.entryHolder_mc["entry"+index];
		selectedEntry.enabled = false;
		selectedEntry.label_txt.htmlText = "<b>"+selectedEntry.labelText+"</b>";
		ZigoEngine.doTween(selectedEntry.label_txt, "_tint", color, 0);
		//ZigoEngine.doTween(selectedEntry.img_border_mc, "_tint", color, 0);
		selectedEntry.img_border_mc._visible = true;
		this.lastPLEntryClicked = selectedEntry;
	};
	
	function showPlaylist(duration:Number){
		//trace("\t VIEW showPlaylist");
		
		this.lastOptionClicked = options_mc.btn_playlist_mc;
		
		hideOtherOptions(playlist_mc);
		//disable fullscreen button
		controls_mc.btn_fullscreen_mc.enabled = false;
		controls_mc.btn_fullscreen_mc._alpha = 50;
		if(duration == undefined) {
			var duration = 1;
		}
				
		if(nowPlaying_mc) {
			ZigoEngine.doTween(nowPlaying_mc, "_y", 0, duration, "easeInOutExpo");
			this.shrinkVideo(duration);
		}
		
		ZigoEngine.doTween(playlist_mc, "_y", playlist_mc.openY, duration, "easeInOutExpo");

		for(var i in playlist_mc.entryHolder_mc) {
			var entry = playlist_mc.entryHolder_mc[i];
			if(entry != this.lastPLEntryClicked) {
				if(nowPlaying_mc != undefined) {
					entry.enabled = true;
				}
			}
		}
	};

	function hidePlaylist(duration:Number, isFullScreen:Boolean, expandVideo:Boolean) {
		//trace("\t VIEW hidePlaylist");
		if(playlist_mc != undefined) {
			if(!isFullScreen) {
				//hide other option menus except playlist
				hideOtherOptions(playlist_mc);
			
				//re-enable fullscreen button
				controls_mc.btn_fullscreen_mc.enabled = true;
				controls_mc.btn_fullscreen_mc._alpha = 100;
				if(duration == undefined) {
					var duration = 1;
				}

				for(var i in playlist_mc.entryHolder_mc) {
					var entry = playlist_mc.entryHolder_mc[i];
					if(nowPlaying_mc != undefined) {
						entry.enabled = false;
					}
				}
				if(nowPlaying_mc) {
					ZigoEngine.doTween(nowPlaying_mc, "_y", nowPlaying_mc.closedY, duration, "easeInOutExpo");
					if(expandVideo) {
						this.expandVideo(1);				
					} else {
						this.expandVideo(0);
						this.centerVideo();
					}
				}
				ZigoEngine.doTween(playlist_mc, "_y", playlist_mc.closedY, duration, "easeInOutExpo");			
			} else {
				playlist_mc._y = playlist_mc.closedY;
				nowPlaying_mc._y = nowPlaying_mc.closedY;
				playlist_mc._visible = false;
				nowPlaying_mc._visible = false;
			}
		}
	}
	
	function updateNowPlaying(title:String, desc:String, color:String, titleFontSize:String, descFontSize:String){
		//trace("\t VIEW updateNowPlaying "+color);
		var txt = "<font color='#"+color+"' size='"+titleFontSize+"'><b>NOW PLAYING:</b></font>";
		if(title == undefined) {
			title = "No Video Title Available";
		}
		
		if(desc == undefined) {
			desc = "No description is currently available.";
		}
		
		txt += newline + "<font size='"+titleFontSize+"'>"+title+"</font>";
		txt += newline + "<font size='"+descFontSize+"' color='#999999'>"+desc+"</font>";
		nowPlaying_mc.label_txt.htmlText = txt;
	};

	// ===========================================================
	// - OPTIONS MENU
	// ===========================================================

	function optionOver(option:String) {
		//trace("\t VIEW optionOver");
		var mc = options_mc['btn_'+option.toLowerCase()+'_mc'];
		ZigoEngine.doTween(mc, "_tint", controller.accentColor, 0);
	}

	function optionOut(option:String) {
		//trace("\t VIEW optionOut");
		var mc = options_mc['btn_'+option.toLowerCase()+'_mc'];
		if(mc != this.lastOptionClicked) {
			ZigoEngine.doTween(mc, "_tint", null , 0);			
		}
	}

	function optionSelected(option:String){
		trace("\t VIEW optionSelected");
		var mc = options_mc['btn_'+option.toLowerCase()+'_mc'];
		if(mc != this.lastOptionClicked) {
			ZigoEngine.doTween(mc, "_tint", controller.accentColor, 0);
		} else {
			ZigoEngine.doTween(mc, "_tint", null , 0);
		}
		if(this.lastOptionClicked != undefined) {
			ZigoEngine.doTween(this.lastOptionClicked, "_tint", null , 0);			
		}

		//this.lastOptionClicked = mc;
	};
	
	function toggleOptionsMenu(state:Boolean, duration:Number){
		////trace("\t VIEW toggleOptionsMenu "+state);
		if(state) {
			ZigoEngine.doTween(options_mc, "_y", options_mc.openY, duration, "easeInOutExpo", 0, {scope:this, func:"toggleOptionButtons", args:true});
		} else {
			resetOptionsMenu();
			toggleOptionButtons(false);
			ZigoEngine.doTween(options_mc, "_y", options_mc.closeY, duration, "easeInOutExpo", 0, {scope:this, func:"toggleOptionButtons", args:false});
			if(duration == 0) {
				options_mc._visible = false;
			}
		}
	};	

	function resetOptionsMenu() {
		//trace("\t VIEW resetOptionsMenu");
		for(var i in options_mc) {
			var mc = options_mc[i];
			if(mc.id != undefined) {
				this.optionOut(mc.id);		
			}
		}
	}
	
	// ===========================================================
	// - OPTIONS
	// ===========================================================
	function setTextListeners() {
		trace("\t VIEW setTextListeners")
		//for age text boxes
		Selection.addListener(txtListener);
		
		/*txtListener.onChanged = function(textfield_txt:TextField) {
			//trace("onChanged");
			//textfield_txt.previousText = textfield_txt.text;
		};*/
		
		txtListener.onSetFocus = function(oldFocus, newFocus) {
			//trace("onSetFocus")
			if(newFocus.text == newFocus.defaultText) {
				newFocus.text = "";
			}
			if(oldFocus.text == "") {
				oldFocus.text = oldFocus.defaultText;
			}
		}
	}

	function hideOption(optionName:Object) {
		trace("\t VIEW hideOption");
		if(typeof optionName == "string") {
			var mc = this[optionName.toLowerCase()+"Box"];
		} else {
			var mc = optionName;
		}
				
		mc.removeMovieClip();
		this.lastOptionClicked = null;
		controller.lastOption = null;
		resetOptionsMenu();
	}
	
	function hideOtherOptions(box:MovieClip){
		trace("\t VIEW hideOtherOptions");
		//close any open option windows 
		var options = [emailBox, linkBox, prefsBox, embedBox, playlist_mc];
		var optionCount = options.length;

		for(var i=0;i<optionCount;i++) {
			var option = options[i];
			if(option != playlist_mc) {
				if(box != option) {
					if(option != undefined) {
						option.removeMovieClip();
					}
				}				
			} else {
				if(box != playlist_mc) {
					controller.hidePlaylist();
				}
			}
		}
	};

	//set global functions for option windows
	function setWindow(box:MovieClip, title:String, windowWidth:Number){
		//trace("\t VIEW setWindow");
		//set size of background box
		if(windowWidth == undefined) {
			var windowWidth = 290;
		}
		
		hideOtherOptions(box);
			
		box.window_mc.btn_close_mc.onRelease = DelegateArgs.create(this, hideOption, box);

		//sets title of box
		box.window_mc.title_txt.autoSize = true;
		box.window_mc.title_txt.htmlText = title;
		box.window_mc.title_txt._x = windowWidth/2 - box.window_mc.title_txt._width/2;
		
		//set y pos of error box;
		box.window_mc.error_txt._y = Math.ceil(box.window_mc.title_txt._y + box.window_mc.title_txt._height);
			
		box.window_mc.bg_mc._width = windowWidth;
		box._x = Math.floor(this.videoWidth/2 - box._width/2);
		
		//position close button
		box.window_mc.btn_close_mc._x = box.window_mc.bg_mc._width - 20;
		
		//set box height
		if(box.btn_age || box.btn_bandwidth) {
			box.window_mc.bg_mc._height = Math.ceil(box._height) - 10;
		} else {
			box.window_mc.bg_mc._height = Math.ceil(box._height) + 10;			
		}

		//center y
		box._y = Math.floor(this.videoHeight/2 - box._height/2);
		
	};
	
	//set up a button
	function setBoxButton(btn:MovieClip, label:String, color:String){
		//trace("\t VIEW setBoxButton");
		
		btn.label_txt.autoSize = true;
		btn.label_txt.text = label;
		var minWidth = Math.max(Math.ceil(btn.label_txt._width), 40);
		btn.bg_mc._width = minWidth + 8;
		btn.label_txt._x = Math.floor((btn.bg_mc._width/2) - (btn.label_txt._width/2));

		btn.onRollOver = function() {
			ZigoEngine.doTween(this.label_txt, "_tint", color, 0);
//			FuseFMP.setFilterProps(this.bg_mc, 'DropShadow', { blurX:2, blurY:2, quality:5, angle:0, distance:0, color:color});
		}

		btn.onRollOut = btn.onReleaseOutside = function() {
			ZigoEngine.doTween(this.label_txt, "_tint", null, 0);
//			FuseFMP.setFilterProps(this.bg_mc, 'DropShadow', { blurX:2, blurY:2, quality:5, angle:0, distance:0, color:"000000"});
		}
	};
	
	//embed box
	function showEmbed(code:String, title:String, color:String){
		trace("\t VIEW showEmbed");

		this.lastOptionClicked = options_mc.btn_embed_mc;
		
		embedBox = rootMC.attachMovie('embedBox_id', 'embedBox_mc', rootMC.getNextHighestDepth());
		
		embedBox.embed_txt.htmlText = code;
		
		//copy to clip board
		var copyBtn = embedBox.attachMovie('btn_global_id', 'btn_copy_mc', embedBox.getNextHighestDepth());
		this.setBoxButton(copyBtn, "Copy to Clipboard", color);
		copyBtn._x = 60;
		copyBtn._y = embedBox.embed_txt._y + embedBox.embed_txt._height + 10;
		copyBtn.onRelease = DelegateArgs.create(controller, controller.copyToClipboard, code);

		//close/cancel button
		var cancelBtn = embedBox.attachMovie('btn_global_id', 'btn_cancel_mc', embedBox.getNextHighestDepth());
		this.setBoxButton(cancelBtn, "Close", color);
		cancelBtn._x = 180;
		cancelBtn._y = embedBox.embed_txt._y + embedBox.embed_txt._height + 10;
		cancelBtn.onRelease = DelegateArgs.create(this, hideOption, embedBox);
		
		setWindow(embedBox, title);
	};

	//link box
	function showLink(title:String, link:String, color:String){
		//trace("\t VIEW showLink");

		this.lastOptionClicked = options_mc.btn_link_mc;
		
		linkBox = rootMC.attachMovie('linkBox_id', 'linkBox_mc', rootMC.getNextHighestDepth());

		linkBox.link_txt.text = link;
		
		var boxBottom = linkBox.link_txt._y + linkBox.link_txt._height;
		
		//copy to clip board
		var copyBtn = linkBox.attachMovie('btn_global_id', 'btn_copy_mc', linkBox.getNextHighestDepth());
		this.setBoxButton(copyBtn, "Copy to Clipboard", color);
		copyBtn._x = 60;
		copyBtn._y = boxBottom+10;
		copyBtn.onRelease = DelegateArgs.create(controller, controller.copyToClipboard, link);

		//copy to clip board
		var cancelBtn = linkBox.attachMovie('btn_global_id', 'btn_cancel_mc', linkBox.getNextHighestDepth());
		this.setBoxButton(cancelBtn, "Close", color);
		cancelBtn._x = 180;
		cancelBtn._y = boxBottom+10;
		cancelBtn.onRelease = DelegateArgs.create(this, hideOption, linkBox);
		
		setWindow(linkBox, title);
		
	};
	
	//email box
	function showEmail(title:String, color:String) {
		//trace("\t VIEW showEmail");
	
		this.lastOptionClicked = options_mc.btn_email_mc;
	
		emailBox = rootMC.attachMovie('emailBox_id', 'emailBox_mc', rootMC.getNextHighestDepth());
		
		var sendBtn = emailBox.attachMovie('btn_global_id', 'btn_send_mc', emailBox.getNextHighestDepth());

		this.setBoxButton(sendBtn, "Send", color);
		
		sendBtn.onRelease = DelegateArgs.create(controller, controller.setEmail, emailBox.yourEmail_txt, emailBox.friendEmail_txt, emailBox.msg_txt);

		sendBtn._x = emailBox.msg_txt._width - sendBtn._width;
		sendBtn._y = emailBox.msg_txt._y + emailBox.msg_txt._height + 10;
		
		setWindow(emailBox, title);
	};
	
	//when email is attempted to be sent
	function sendEmail(success:Boolean, msg:String) {
		trace("\t VIEW sendEmail");
		if(success) {
			emailBox.removeMovieClip();
			sentEmailBox(msg);
			//emailBox.window_mc.error_txt.htmlText = "<font color='#FF0000'>"+msg+"</font>";
		} else {
			emailBox.window_mc.error_txt.htmlText = "<font color='#FF0000'>"+msg+"</font>";
		}
	}
	
	function sentEmailBox(msg:String) {
		trace("\t VIEW sentEmailBox");
		
		emailBox = rootMC.attachMovie('emailSentBox_id', 'emailBox_mc', rootMC.getNextHighestDepth());
		
		var cancelBtn = emailBox.attachMovie('btn_global_id', 'btn_cancel_mc', emailBox.getNextHighestDepth());
		this.setBoxButton(cancelBtn, "Close", controller.accentColor);
		
		var windowWidth = 200;
		
		cancelBtn.onRelease = DelegateArgs.create(this, hideOption, emailBox);

		cancelBtn._x = windowWidth/2 - cancelBtn._width/2;
		cancelBtn._y = 60;
		
		setWindow(emailBox, msg, windowWidth);
		
	};
	
	//pref box
	function showPrefs(isSetUp:Boolean, title:String, birthday:Array, speed:String, color:String, mode:String){
		trace("\t VIEW showPrefs");

		this.lastOptionClicked = options_mc.btn_prefs_mc;

		//make sure prefsBox gets removed from switching between tabs
		if (prefsBox != undefined) {
			prefsBox.removeMovieClip();
		}
		
		prefsBox = rootMC.attachMovie('prefBox_id', 'prefsBox_mc', rootMC.getNextHighestDepth());

		if(!isSetUp) {
			prefsBox.btn_bandwidth.onRelease = DelegateArgs.create(controller, controller.showPrefs, false, "speed");	
			prefsBox.btn_age.onRelease = DelegateArgs.create(controller, controller.showPrefs, false, "age");
			
			switch(mode) {
				case "speed":
					prefsBox.btn_bandwidth.enabled = false;
					ZigoEngine.doTween(prefsBox.btn_bandwidth.label_txt, "_tint", color, 0);
					ZigoEngine.doTween(prefsBox.btn_age.label_txt, "_tint", "#666666",0);
				break;
				default:
					prefsBox.btn_age.enabled = false;
					ZigoEngine.doTween(prefsBox.btn_age.label_txt, "_tint", color,0);
					ZigoEngine.doTween(prefsBox.btn_bandwidth.label_txt, "_tint", "#666666",0);
				break;
				
			}
			prefsBox.btn_age.onRollOver = prefsBox.btn_bandwidth.onRollOver = function() {
				ZigoEngine.doTween(this.label_txt, "_tint", color, 0);
			}
			
			prefsBox.btn_age.onRollOut = prefsBox.btn_bandwidth.onRollOut = function() {
				ZigoEngine.doTween(this.label_txt, "_tint", "#666666", 0);
			}
		} else {
			//hide close button and tabs			
			prefsBox.window_mc.btn_close_mc._visible = prefsBox.btn_bandwidth._visible = prefsBox.btn_age._visible = false;
		}
		
		switch (mode) {
			case "speed":
				//make tab looked selected
				prefsBox.btn_bandwidth.gotoAndStop(2);
				prefsBox.btn_bandwidth.swapDepths(prefsBox.window_mc);
				
				var speeds = ["low","medium","high"];
				var speedLabels = ["Low (Dial-up)", "Medium (DSL,Cable)","High (LAN, T1)"];
				var startY = 70;
				for (var i =0;i<speeds.length;i++) {
					var option = prefsBox.attachMovie('btn_speed_id', 'speed_mc'+i, i);
					option._x = 70;
					option._y = startY + 20*i;
					//color radio button
					ZigoEngine.doTween(option.radio_mc.circle_mc, "_tint", color, 0);
					option.radio_mc.circle_mc._visible = false;
					option.label_txt.htmlText = speedLabels[i];
					option.speed = speeds[i];
					if(option.speed == speed) {
						option.radio_mc.circle_mc._visible = true;
					}
					option.onRelease = DelegateArgs.create(controller, controller.selectBandwidth, option.speed)
					
					var setBtn = prefsBox.attachMovie('btn_global_id', 'btn_age_mc', prefsBox.getNextHighestDepth());

					this.setBoxButton(setBtn, "OK", color);

					setBtn._x = 200;
					setBtn._y = 140;
					
					//setBtn.onRelease = DelegateArgs.create(this, hideOption, prefsBox);
					setBtn.onRelease = DelegateArgs.create(controller, controller.confirmBandwidth);
				}
			break;	
			default:
				//make tab looked selected
				prefsBox.btn_age.gotoAndStop(2);
				prefsBox.btn_age.swapDepths(prefsBox.window_mc);
				prefsBox.btn_bandwidth.swapDepths(prefsBox.window_mc);

				var startY = 95;
				var startX = 90;
				var boxes = birthday.length;
				var sizes = [2,1,2,1,4];
				var widths = [24,10,24,10,38];
				var tabOrder = [1,100,2,200,3];
				var boxPreFill = ["MM","","DD","","YYYY"];
				var runningX = 0;
				var depths = 10;
				var disableCount = 0;
				for (var i=0;i<boxes;i++) {
					var currInputBox = prefsBox.attachMovie('input_date_id','box'+i,depths--);
					currInputBox._x = startX + runningX;
					currInputBox._y = startY;
					//set textbox properties
					currInputBox.date_txt._width = widths[i];
					if(i != 1 && i != 3) {
						if (birthday[i] == undefined || birthday[i] == "undefined" || birthday[i] == boxPreFill[i]) {
							currInputBox.date_txt.selectable = true;
						}
						else {
							currInputBox.date_txt.selectable = false;
							disableCount++;
						}
						currInputBox.date_txt.autoSize = false;
						currInputBox.date_txt.tabIndex = tabOrder[i];
						var borderMC = prefsBox.attachMovie('input_border_id', 'border'+i, depths--);
						borderMC._x = startX + runningX - 4;
						borderMC._y = startY - 1;
						borderMC._width = widths[i] + 6;
						borderMC._height += 8;
						ZigoEngine.doTween(borderMC.border_mc, "_tint", color, 0);
						runningX += widths[i] + 4;
						currInputBox.date_txt.restrict = "0-9";
						//listener for text focus
						currInputBox.date_txt.addListener(txtListener);
					} else {
						ZigoEngine.doTween(currInputBox.date_txt, "_tint", "#FFFFFF",0);
						currInputBox.date_txt.selectable = false;
						runningX += widths[i] + 4;
						currInputBox.date_txt.restrict = "/";
					}
					currInputBox.date_txt.multiline = false;

					currInputBox.date_txt.maxChars = sizes[i];
					currInputBox.date_txt.defaultText = boxPreFill[i];
					if (birthday[i] == undefined || birthday[i] == "undefined") {
						currInputBox.date_txt.text = boxPreFill[i];
						//currInputBox.date_txt.text = "";
					} else {
						currInputBox.date_txt.text = birthday[i];
					}
					
				}
				if (disableCount != 3) {
					//Set Age Button
					var setBtn = prefsBox.attachMovie('btn_global_id', 'btn_age_mc', prefsBox.getNextHighestDepth());
					this.setBoxButton(setBtn, "Set Age", color);
					setBtn._x = 200;
					setBtn._y = 130;
					if(!isSetUp) {
						setBtn.onRelease = DelegateArgs.create(this, updateAge);
					} else {
						setBtn.onRelease = DelegateArgs.create(this, initPref);
					}
				}
			break;
		}
		
		setWindow(prefsBox, title);
	};
	
	//send birthday to controller
	function updateAge(){
		//trace("\t VIEW updateAge");
		var dateValid = controller.validateDate(prefsBox["box0"].date_txt.text,prefsBox["box2"].date_txt.text,prefsBox["box4"].date_txt.text);
		
		if(dateValid) {
			controller.updateAge(prefsBox["box0"].date_txt.text,prefsBox["box2"].date_txt.text,prefsBox["box4"].date_txt.text);
			hideOption(prefsBox);
		} else {
			prefsBox.window_mc.error_txt.htmlText = "<font color='#FF0000'>Invalid date. Please try again.</font>";
		}
	};
	
	//change speed radio buttons
	function setSpeed(speed:String){
		//trace("\t VIEW setSpeed");
		if(prefsBox != undefined) {
			for (var i in prefsBox) {
				var option = prefsBox[i];
				if(option.speed == speed) {
					option.radio_mc.circle_mc._visible = true;
				} else {
					option.radio_mc.circle_mc._visible = false;
				}
			}
		}
	};

	//if preferences screen is for inital setup
	function initPref(){
		trace("\t VIEW initPref");
		var dateValid = controller.validateDate(prefsBox["box0"].date_txt.text,prefsBox["box2"].date_txt.text,prefsBox["box4"].date_txt.text);
		
		if(dateValid) {
			controller.setBirthday(prefsBox["box0"].date_txt.text,prefsBox["box2"].date_txt.text,prefsBox["box4"].date_txt.text);
			hideOption(prefsBox);
			controller.setUp();
		} else {
			prefsBox.window_mc.error_txt.htmlText = "<font color='#FF0000'>Invalid date. Please try again.</font>";
		}
	};

	// ===========================================================
	// - BUTTONS
	// ===========================================================
	
	function next(){
		var btn = controls_mc.btn_next_mc;
		buttonReset(btn);
	};
	
	function prev(){
		var btn = controls_mc.btn_prev_mc;
		buttonReset(btn);
	};
	
	function buttonReset(btn:MovieClip){
		//trace("\t VIEW buttonCheck");
		if(btn.over && btn.enabled) {
			ZigoEngine.doTween(btn.icon_mc, "_tint", btn.accentColor , 0);
		} else {
			ZigoEngine.doTween(btn.icon_mc, "_tint", null , 0);			
		}		
		
	};
	
	function togglePrevButton(state:Boolean){
		var prevBtn = controls_mc.btn_prev_mc;
		prevBtn.enabled = state;
		if (state) {
			prevBtn._alpha = 100;
		} else {
			prevBtn._alpha = 50;
			ZigoEngine.doTween(prevBtn.icon_mc, "_tint", null, 0);
		} 
	};

	function toggleNextButton(state:Boolean){
		//trace("\t VIEW toggleNextButton")
		var nextBtn = controls_mc.btn_next_mc;
		nextBtn.enabled = state;
		if (state) {
			nextBtn._alpha = 100;
		} else {
			nextBtn._alpha = 50;
			ZigoEngine.doTween(nextBtn.icon_mc, "_tint", null, 0);
		}
	};
	
	function toggleOptionButtons(state:Boolean){
		////trace("\t VIEW toggleOptionButtons");
		for (var i in options_mc) {
			var btn = options_mc[i];
			btn.enabled = state;
		}
	};

	function togglePlaylistItems(state:Boolean) {
		trace("\t VIEW togglePlaylistItems")
		for (var i in playlist_mc.entryHolder_mc) {
			var btn = playlist_mc.entryHolder_mc[i];
			btn.enabled = state;
			if(state) {
				ZigoEngine.doTween(btn.label_txt, "_tint", null, 0);
			} else {
				ZigoEngine.doTween(btn.label_txt, "_tint", "#666666", 0);				
				btn.img_border_mc._visible = state;
			}


		}
	}
	
	function togglePlayPauseButtons(status:String) {
		trace("\t VIEW togglePlayPauseButtons");
		trace("\t\t -------> "+status)
		switch (status) {
			case "playing":
				ZigoEngine.doTween(controls_mc.btn_play_mc, "_tint", null, 0);
				controls_mc.btn_play_mc.enabled = false;
				controls_mc.btn_pause_mc.enabled = true;
				controls_mc.btn_play_mc._visible = false;
				controls_mc.btn_pause_mc._visible = true;
				controls_mc.btn_play_mc._alpha = 50;
				controls_mc.btn_pause_mc._alpha = 100;
			break;
			case "paused":
				ZigoEngine.doTween(controls_mc.btn_pause_mc, "_tint", null, 0);
				controls_mc.btn_play_mc.enabled = true;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 100;
				controls_mc.btn_pause_mc._alpha = 50;
			break;
			case "stopped":
				controls_mc.btn_play_mc.enabled = true;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 100;
				controls_mc.btn_pause_mc._alpha = 50;
			break;
			case "disabled":
				ZigoEngine.doTween(controls_mc.btn_play_mc, "_tint", null, 0);
				ZigoEngine.doTween(controls_mc.btn_pause_mc, "_tint", null, 0);	
				controls_mc.btn_play_mc.enabled = false;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 50;
				controls_mc.btn_pause_mc._alpha = 50;

			break;
		}	
	}

	// ===========================================================
	// - FULLSCREEN / NORMAL SCREEN
	// ===========================================================
	
	function showFullScreen(){
		trace("\t VIEW showFullScreen");
		var aspectRatio = 3/4;

		var nWidth = Stage.width;
		var nHeight = Stage.width * aspectRatio;
		var yPos = Stage.height/2 - nHeight/2;

		//bg
		bg_mc._width = Stage.width;
		bg_mc._height = Stage.height;
		
		//size video and preview
		//preview_mc.setMaxSize(nWidth, nHeight, true);
		//player_mc.setSize(nWidth, nHeight);
		preview_mc._width = Stage.width;
		preview_mc._height = Stage.height;

		
		//resize transparent movieclip for ads to be clickable
		adClick_mc._width = nWidth;
		adClick_mc._height = nHeight;
		
		centerVideo();

		//move controls
		controls_mc._parent._x = (Stage.width/2) - (controls_mc.bg_mc._width/2);
		controls_mc._parent._y = Stage.height - (controls_mc._y + controls_mc.bg_mc._height) - 20;
		//playlist
		playlist_mc._visible = false;
		//options		
		options_mc._visible = false;
		//place logo scaled up
		placeLogo(logo_mc.img_mc, 250);
	};
	
	function showNormalScreen (){
		trace("\t VIEW showNormalScreen");
		//size video and preview
		//preview_mc.setMaxSize(this.viewportWidth, this.viewportWidth, true);
		preview_mc._width = this.videoWidth;
		preview_mc._height = this.videoHeight;
		
		//resize transparent movieclip for ads to be clickable
		adClick_mc._width = this.videoWidth;
		adClick_mc._height = this.videoHeight;
		
		centerVideo();

		//bg
		bg_mc._width = this.viewportWidth;
		bg_mc._height = this.viewportHeight;

		//reset preview position
		preview_mc._y = 0;
		preview_mc._x = 0;

		//controls
		controls_mc._visible = true;
		controls_mc._alpha = 100;		
		controls_mc._parent._x = 0;
		controls_mc._parent._y = 0;
		
		options_mc._visible = true;
		
		playlist_mc._visible = true;
		
		placeLogo(logo_mc.img_mc);
	};

	// ===========================================================
	// - VIDEO
	// ===========================================================

	function shrinkVideo(duration:Number){
		trace("\t VIEW shrinkVideo");
		if(duration != 0) {
			ZigoEngine.doTween(player_mc, ["_width","_height","_x","_y"], [this.nowPlayingWidth, this.nowPlayingHeight, 10, 10], duration, "easeInOutExpo", 0);
			ZigoEngine.doTween(preview_mc, ["_width","_height","_x","_y"], [this.nowPlayingWidth, this.nowPlayingHeight, 10, 10], duration, "easeInOutExpo", 0);
		} else {
			player_mc._x = player_mc._y = preview_mc._x = preview_mc._y = 10;
			player_mc._width = this.nowPlayingWidth;
			player_mc._height = this.nowPlayingHeight;
		}
	};

	function expandVideo(duration:Number) {	
		trace("\t VIEW expandVideo");
		
		if(duration == undefined) {
			var duration = 1;
		}
		if(duration != 0) {
			ZigoEngine.doTween(player_mc, ["_scale","_x","_y"], [100, player_mc.centerX, player_mc.centerY], 1, "easeInOutExpo", 0);
			ZigoEngine.doTween(preview_mc, ["_width","_height","_x","_y"], [this.videoWidth, this.videoHeight, 0, 0], 1, "easeInOutExpo", 0);
		} else {
			player_mc._x = player_mc.centerX;
			player_mc._y = player_mc.centerY;
			player_mc._xscale = 100;
			player_mc._yscale = 100;
			preview_mc._x = preview_mc._y = 0;
			preview_mc._width = this.videoWidth;
			preview_mc._height = this.videoHeight;
		}
	};

	function centerVideo(fullScreen:Boolean) {
		trace("\t VIEW centerVideo");

		//get new height based on aspect ratio and the width of the video at the right size
		if(Stage.displayState == "normal") {
			var vWidth = this.videoWidth;
			var vHeight = Math.round((player_mc.metadata.height * vWidth) / player_mc.metadata.width);
			if(vHeight > this.videoHeight) {
				var vHeight = this.videoHeight;
				var vWidth = Math.round((player_mc.metadata.width * vHeight) / player_mc.metadata.height);
			}
		} else if (Stage.displayState == "fullScreen") {
			var vWidth = Stage.width;
			var vHeight = Math.round((player_mc.metadata.height * vWidth) / player_mc.metadata.width);
			if(vHeight > Stage.height) {
				var vHeight = Stage.height;
				var vWidth = Math.round((player_mc.metadata.width * vHeight) / player_mc.metadata.height);
			}
		}
		
		//set size
		player_mc.setSize(vWidth, vHeight);
		
		if(Stage.displayState == "normal") {
			var topBuffer = Math.floor((this.videoHeight - vHeight)/2);
			var leftBuffer = Math.floor((this.videoWidth - vWidth)/2);
		} else if (Stage.displayState == "fullScreen") {
			var topBuffer = Math.floor((Stage.height - vHeight)/2);
			var leftBuffer = Math.floor((Stage.width - vWidth)/2);
		}
		
		player_mc.centerY = topBuffer;
		player_mc.centerX = leftBuffer;
		player_mc._y = player_mc.centerY;
		player_mc._x = player_mc.centerX;

	}

	// ===========================================================
	// - LOGO
	// ===========================================================

	function createLogo(logo:String){
		trace("\t VIEW createLogo");
		logo_mc = rootMC.attachMovie('imageLoader', 'logo_mc', 25);
		logo_mc._alpha = 0;
		logo_mc.onLoadInit = DelegateArgs.create(this, placeLogo, false);
		logo_mc.load(logo);
		logo_mc.onRelease = DelegateArgs.create(controller, controller.launchSiteURL);
	};
	
	function placeLogo(target:MovieClip, scale:Number) {
	//	trace("\t VIEW placeLogo");
		//bottom and right buffer of video screen

		if(scale != undefined && typeof scale == "number") {
			var logoBuffer = 25;
			logo_mc._xscale = scale;
			logo_mc._yscale = scale;
		} else {
			var logoBuffer = 10;
			logo_mc._xscale = 100;
			logo_mc._yscale = 100;
		}
				
		if(Stage.displayState == "normal") {
			logo_mc._x = (this.videoWidth) - (logo_mc._width + logoBuffer);
			logo_mc._y = (this.videoHeight) - (logo_mc._height + logoBuffer);
		} else if (Stage.displayState == "fullScreen") {
			logo_mc._x = Stage.width - (logo_mc._width + logoBuffer);
			logo_mc._y = Stage.height - (logo_mc._height + logoBuffer);
		}
		
		if(!controller.isPlayingAd) {
			ZigoEngine.doTween(logo_mc, "_alpha", 50, .5, "easeInOutExpo");
		} else {
			logo_mc._visible = false;
		}
	}
	
	function toggleLogo(visible:Boolean){
//		trace("\t VIEW toggleLogo "+visible);
		logo_mc._visible = visible;	
	};

	// ===========================================================
	// - ADS
	// ===========================================================
	
	function toggleAdText(visible:Boolean) {
		trace("\t VIEW toggleAdText");
		if(visible) {
			var speed = 1;
			var count = 0;
			var mc1 = adTextHolder_mc.adText1_mc;
			var mc2 = adTextHolder_mc.adText2_mc;
			if(adTextHolder_mc.maskWidth >= mc1._width) {
				//static ad text
				mc1._x = 0;
				mc2._visible = false;
			} else {
				//run ad ticker
				mc1._x = adTextHolder_mc.maskWidth + 20;
				mc2._x = mc1._x + mc1._width + 20;
				adTextHolder_mc.onEnterFrame = function() {
					mc1._x -= speed;
					mc2._x -= speed;
					if(mc1._x <= (0-mc1._width)) {
						mc1._x = mc2._x + mc2._width + 20;
					}
					if(mc2._x <= (0-mc2._width)) {
						mc2._x = mc1._x + mc1._width + 20;
					}
				}
			}
			
			//mouse event
			adTextHolder_mc.onRelease = DelegateArgs.create(controller, controller.launchAdURL);
		} else {
			//stop ticker
			delete adTextHolder_mc.onEnterFrame;
		}
		
		adTextHolder_mc._visible = visible;
	}
	
	function toggleAdClick(visible:Boolean) {
		adClick_mc._visible = visible;
	}
	
}